#pragma once
#include "IBrushSpan.h"

#include "CMILMatrix.h"

class CRasterizerEdgeStore;
class CLayerRasterData;

class CLayer :
	public IBrushSpan
{
public: 
	static HRESULT Create(float rOpacity, CBrush * pOpacityMask, CLayer * * ppLayer);
	virtual XUINT32 AddRef();
	virtual XUINT32 Release();
	virtual HRESULT SetBrush(const CMILMatrix * pWorldTransform, const struct XRECTF_WH * pBrushBounds, CBrush * pBrush);
	virtual XINT32 SolidColor(XUINT32 nCPUCore, XINT32 nY, XUINT32 * prgb);
	virtual void GenerateColors(struct GENCOLORSDATA * pGCD);
	virtual HRESULT GenerateClearType(XUINT32 nCPUCore, XINT32 nX, XINT32 nY, XINT32 nCount, struct ClearTypePixel * paragabScanLine);
	virtual XINT32 IsZeroAlpha();
	virtual XINT32 IsOpaque();
	virtual XUINT32 GetBrushBlendAlpha();
	virtual XBOOL IsLayer();
	virtual XBOOL IsSimpleLayer();
	virtual XINT32 IsLeafBrush();
	void SetHasClearType(XUINT32 bHasClearType);
	virtual XINT32 HasClearType();
	void ResetBounds();
	void UpdateBounds(XINT32 nPixelTop, XINT32 nPixelBottom, XINT32 nPixelLeft, XINT32 nPixelRight);
	void SetIsParentZeroAlpha(XBOOL fIsParentLayerZeroAlpha);
	XINT32 IsEmpty();
	HRESULT SetOpacityMask(CCoreServices * pOpacityMaskBrush, CBrush * pOpacityMaskTransform, CMILMatrix * pOpacityMaskBounds, struct XRECTF_WH * fOpacityMaskBrushChanged);
	void SetClipEdgeStore(CRasterizerEdgeStore * pClipEdgeStore);
	CRasterizerEdgeStore * ClipEdgeStore();
	XINT32 m_nSubpixelBoundsTop;
	XINT32 m_nSubpixelBoundsBottom;
	XINT32 m_nSubpixelBoundsLeft;
	XINT32 m_nSubpixelBoundsRight;
	CRasterizerEdgeStore * m_pRasterizerEdgeStore;
	CLayerRasterData * m_pLayerRasterData;
	struct IBrushSpan * m_pOpacityMask;

protected: 
	CLayer();
	~CLayer();
	XUINT32 m_cRef;
	XUINT32 m_uOpacity;
	XUINT16 m_bHasClearType;
	XUINT16 m_fIsParentZeroAlpha;
	CRasterizerEdgeStore * m_pClipEdgeStore;
public: 
	void NWSetOpacity(float rOpacity);
	HRESULT NWSetOpacityMask(CBrush * pOpacityMaskBrush, CMILMatrix * pOpacityMaskTransform, struct XRECTF_WH * pOpacityMaskBounds, XBOOL fOpacityMaskBrushChanged);
private: 
	void NWResetOpacityMaskData();
	CBrush * m_pNWOpacityMaskBrush;
	struct XRECTF_WH m_NWOpacityMaskBounds;
	CMILMatrix m_NWOpacityMaskTransform;
};